package com.cn.controller.companyManager;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cn.entity.TbCompany;
import com.cn.service.company.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


/**
 * @Author 公司顾客信息管理
 * @Date 2021/6/4 11:31
 * @Package com.cn.controller.companyManager
 * @Version 1.0
 */


@RequestMapping("/companyManager")
@Controller
public class CompanyManagerController{

    @Autowired
    private CompanyService companyService;

    /*
    分页查询所有的公司
     */
    @RequestMapping("/companyList")
    public String allCompany(String name, String companyNo, String owner, @RequestParam(defaultValue = "1") Integer pageNum, Model model){
        Page<TbCompany> page = companyService.allTbCompany(name, companyNo, owner, pageNum);
        model.addAttribute("companys",page);
        model.addAttribute("name",name);
        model.addAttribute("companyNo",companyNo);
        model.addAttribute("owner",owner);
        return "companyList/saved_resource";
    }
    /*
    进入添加公司页面
     */
    @RequestMapping("/addCompanyHtml")
    public String addCompanyHtml(){
        return "/addCompany/saved_resource";
    }
    /*
    添加公司
     */
    @RequestMapping("/addCompany")
    public String addCompany(TbCompany tbCompany){
        companyService.addCompany(tbCompany);
        return "redirect:/companyManager/companyList";
    }
    /*
    进入修改公司信息页面
     */
    @RequestMapping("/updateById")
    public String updateById(Long id,Model model){
        TbCompany tbCompany = companyService.queryById(id);
        model.addAttribute("tbCompany",tbCompany);
        return "/updateCompany/saved_resource";
    }
    /*
    修改公司信息
     */
    @RequestMapping("/updateCompany")
    public String updateCompany(TbCompany tbCompany){
        companyService.updateCompany(tbCompany);
        return "redirect:/companyManager/companyList";
    }
    /*
    根据id删除公司信息
     */
    @RequestMapping("/delById")
    public String delById(Long id){
        companyService.delById(id);
        return "redirect:/companyManager/companyList";
    }
}
